﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace app_common
{
    public class clsWriteFile
    {
        private bool check_exits_file(string path)
        {
            if (System.IO.File.Exists(path))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public void write_line(string text)
        {
            try
            {
                if (!check_exits_file("log.log"))
                {
                    create_log_file();
                }
                FileStream fs = new FileStream("log.log", FileMode.OpenOrCreate, FileAccess.Write);
                StreamWriter m_streamWriter = new StreamWriter(fs);
                m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
                m_streamWriter.WriteLine(DateTime.Now.ToString() + " " + text + "\n");
                m_streamWriter.Flush();
                m_streamWriter.Close();
            }
            catch
            {
            }
        }

        private void create_log_file()
        {
            try
            {
                FileStream fs = File.Open("log.log", FileMode.Create, FileAccess.Write);
            }
            catch { }
        }
    }
}
